package com.itheima.controller;


import com.itheima.pojo.User;
import com.itheima.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;

/**
 * @RestController  方法返回全为String
 */
@RestController
public class HelloController {

    @Qualifier("dataSource")
    @Autowired
    private DataSource dataSource;

    @Value("${itheima.url}")
    private String itheimaurl;

    @Value("${itcast.url}")
    private  String itcasturl;

    @Autowired
    private UserService userService;

    /**
     * 根据id查询user
     * @param id
     * @return
     */
    @GetMapping("/user/{id}")
    public User queryById(@PathVariable Long id){
        return userService.queryById(id);
    }

    @GetMapping
    public String hello(){
        System.out.println(itcasturl);
        System.out.println(itheimaurl);
        System.out.println("DataSource = "+ dataSource);
        return "Hello, Spring boot";
    }
}
